package com.yunhe.policyfulfillment.policyful.controller;

import com.yunhe.common.exception.ArgumentErrorException;
import com.yunhe.common.model.ResultObject;
import com.yunhe.common.model.mybatis.PageResult;
import com.yunhe.policyfulfillment.policyful.domain.PolicyCommonQuestion;
import com.yunhe.policyfulfillment.policyful.model.PolicyCommonQuestionVo;
import com.yunhe.policyfulfillment.policyful.model.PolicyCommonQuestionVo2;
import com.yunhe.policyfulfillment.policyful.service.PolicyCommonQuestionService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @description policy_common_question
 * @author zb
 * @date 2021-10-12
 */
@Api(value = "PolicyCommonQuestion", description = "常见问题维护", tags = {"常见问题维护"})
@RestController
@RequestMapping(value = "/policyCommonQuestion")
public class PolicyCommonQuestionController {

    @Autowired
    private PolicyCommonQuestionService policyCommonQuestionService;

    /**
     * 新增
     *
     * @author zb
     * @date 2021/10/12
     **/
    @ApiOperation("新增常见问题")
    @PostMapping("/createPolicyCommonQuestion")
    public ResponseEntity<ResultObject> createPolicyCommonQuestion(@RequestBody PolicyCommonQuestion policyCommonQuestion) throws ArgumentErrorException {
        policyCommonQuestionService.createPolicyCommonQuestion(policyCommonQuestion);
        return new ResponseEntity<>(new ResultObject<>(), HttpStatus.OK);
    }

    /**
     * 刪除
     *
     * @author zb
     * @date 2021/10/12
     **/
    @ApiOperation("根据ids批量删除")
    @DeleteMapping("/deletePolicyCommonQuestion")
    public ResponseEntity<ResultObject> deletePolicyCommonQuestion(@RequestBody List<Long> ids) {
        policyCommonQuestionService.patchDeletePolicyCommonQuestion(ids);
        return new ResponseEntity<>(new ResultObject<>(), HttpStatus.OK);
    }

    /**
     * 编辑
     *
     * @author zb
     * @date 2021/10/12
     **/
    @ApiOperation("编辑常见问题")
    @PostMapping("/updatePolicyCommonQuestion")
    public ResponseEntity<ResultObject> updatePolicyCommonQuestion(@RequestBody PolicyCommonQuestion policyCommonQuestion) {
        policyCommonQuestionService.updatePolicyCommonQuestion(policyCommonQuestion);
        return new ResponseEntity<>(new ResultObject<>(), HttpStatus.OK);
    }

    /**
     * 禁用/发布
     *
     * @author zb
     * @date 2021/10/12
     **/
    @ApiOperation(value = "禁用/发布常见问题")
    @PostMapping("/disableOrRelease")
    public ResponseEntity<ResultObject> disableOrRelease(@RequestBody PolicyCommonQuestionVo2 vo) throws ArgumentErrorException {
        policyCommonQuestionService.disableOrRelease(vo);
        return new ResponseEntity<>(new ResultObject<>(), HttpStatus.OK);
    }

    /**
     * 查询 根据主键 id 查询
     *
     * @author zb
     * @date 2021/10/12
     **/
    @ApiOperation("根据id查询常见问题")
    @GetMapping("/findPolicyCommonQuestionById")
    public ResponseEntity<ResultObject<PolicyCommonQuestion>> findPolicyCommonQuestionById(@RequestParam(value = "id", required = true) int id) {
        return new ResponseEntity<>(new ResultObject(policyCommonQuestionService.findPolicyCommonQuestionById(id)), HttpStatus.OK);
    }

    /**
     * 根据条件查询列表
     *
     * @author zb
     * @date 2021/10/12
     **/
    @ApiOperation("根据条件查询列表")
    @PostMapping("/findPolicyCommonQuestionList")
    public ResponseEntity<ResultObject<PageResult<PolicyCommonQuestion>>> findPolicyCommonQuestionListByCondition(@RequestBody PolicyCommonQuestionVo vo) {
        return new ResponseEntity<>(new ResultObject(policyCommonQuestionService.findPolicyCommonQuestionListByCondition(vo)), HttpStatus.OK);
    }

}

